package com.uenpay.im.ui.old.activity.choosemorepic;

import android.content.Context;
import android.graphics.Bitmap;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.Checkable;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.aswife.ui.MaskImageView;
import com.uenpay.im.R;

public class PhotoGridItem extends RelativeLayout implements Checkable {
	private Context mContext;
	private boolean mCheck;
	public MaskImageView mImageView;
	public ImageView mSelect;

	public PhotoGridItem(Context context) {
		this(context, null, 0);
	}

	public PhotoGridItem(Context context, AttributeSet attrs) {
		this(context, attrs, 0);
	}

	public PhotoGridItem(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		mContext = context;
		LayoutInflater.from(mContext).inflate(
				R.layout.photoalbum_gridview_item, this);

		mImageView = (MaskImageView) findViewById(R.id.photo_img_view);
		mSelect = (ImageView) findViewById(R.id.photo_select);
	}

	@Override
	public void setChecked(boolean checked) {
		mCheck = checked;
		if (checked) {
			mSelect.setImageResource(R.drawable.icon_checked);
		} else {
			mSelect.setImageResource(R.drawable.icon_uncheck);
		}
	}

	@Override
	public boolean isChecked() {
		return mCheck;
	}

	@Override
	public void toggle() {
		setChecked(!mCheck);
	}

	public void setImgResID(int id) {
		if (mImageView != null) {
			mImageView.setImageResource(id);

			mImageView.setBackgroundResource(id);
		}
	}

	public void SetBitmap(Bitmap bit) {
		if (mImageView != null) {
			mImageView.setImageBitmap(bit);
		}
	}

	public ImageView getImageView() {
		if (mImageView != null) {

			return mImageView;
		}
		return null;
	}

	public void setUrl(String url) {

		if (mImageView != null) {
			mImageView.setBackgroundResource(R.drawable.icon_default_image);
			mImageView.SetUrl(url);
		}
	}
}
